@echo off
REM scripts/deploy.bat

setlocal enabledelayedexpansion

REM 配置变量
set REGISTRY_URL=localhost:5000
set IMAGE_NAME=gd-data-platform
set VERSION=%1
if "%VERSION%"=="" set VERSION=latest
set FULL_IMAGE_NAME=%REGISTRY_URL%/%IMAGE_NAME%:%VERSION%

echo 开始部署应用...
echo 镜像名称: %FULL_IMAGE_NAME%

REM 检查镜像是否存在
docker image inspect %FULL_IMAGE_NAME% >nul 2>&1
if errorlevel 1 (
    echo 镜像不存在，正在拉取...
    docker pull %FULL_IMAGE_NAME%
)

REM 停止现有容器
echo 停止现有容器...
docker-compose down

REM 更新 docker-compose.yml 中的镜像版本
echo 更新镜像版本...
powershell -Command "(Get-Content docker-compose.yml) -replace 'image: .*', 'image: %FULL_IMAGE_NAME%' | Set-Content docker-compose.yml"

REM 启动服务
echo 启动服务...
docker-compose up -d

REM 等待服务启动
echo 等待服务启动...
timeout /t 30 /nobreak >nul

REM 健康检查
echo 执行健康检查...
call scripts\health-check.bat

echo 部署完成！
echo 访问地址: http://localhost
